package com.yue.jpa.main;

import com.yue.jpa.entity.Employee;
import com.yue.jpa.service.EmployeeService;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * 功能描述: TODO <br/>
 * 创建时间: 2016/9/2<br/>
 *
 * @author QiuYang
 */
public class EmployeeServiceTest {

    public static void main(String[] args) {
        test2();

    }

    public static void test1() {
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("EmployeeService");
        EntityManager entityManager = entityManagerFactory.createEntityManager();

        EmployeeService service = new EmployeeService(entityManager);

        entityManager.getTransaction().begin();

//        service.createEmployee(158, "John Doe", 45000);
        Employee employee = service.findEmployee(158);
//        System.out.println(employee.getId() + " " + employee.getName() + " " + employee.getSalary());

        entityManager.getTransaction().commit();
        entityManager.close();
        entityManagerFactory.close();
    }

    public static void test2() {
        EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("EmployeeService");
        EntityManager entityManager = entityManagerFactory.createEntityManager();

        EmployeeService service = new EmployeeService(entityManager);

        entityManager.getTransaction().begin();

        Employee employee = new Employee();
        employee.setName("test");
        service.create(employee);
//        System.out.println(employee.getId() + " " + employee.getName() + " " + employee.getSalary());

        entityManager.getTransaction().commit();
        entityManager.close();
        entityManagerFactory.close();
    }
}
